/**
 * 
 */
package me.myachievements.web.restricted.goal;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import me.myachievements.persistence.goal.Goal;
import me.myachievements.persistence.goal.GoalPersistenceManager;
import me.myachievements.persistence.tag.Tag;

import me.myachievements.web.ErrorPage;
import me.myachievements.web.goal.CreateGoalFormPanel;
import me.myachievements.web.goal.GoalForm;
import me.myachievements.web.goal.GoalFormPanel;
import me.myachievements.web.goal.UpdateGoalForm;
import me.myachievements.web.goal.UpdateGoalFormPanel;
import me.myachievements.web.restricted.RestrictedPage;
import me.myachievements.web.tag.GoalTagForm;
import me.myachievements.web.tag.GoalTagRemoveForm;
import me.myachievements.web.tag.GoalTagsSelectorPanel;
import me.myachievements.web.tag.TagForm;
import me.myachievements.web.tag.GoalTagAddForm;
import me.myachievements.web.tag.GoalTagFormModel;

/**
 * @author besseym
 *
 */
public class GoalUpdatePage extends RestrictedPage {
	
	@SpringBean(name="goalPersistenceManager")
	GoalPersistenceManager goalPersistenceManager;

	/**
	 * Constructor
	 * @param pageParameters
	 */
	public GoalUpdatePage(PageParameters pageParameters) {
		 
		if(!pageParameters.containsKey("id")) {
			this.setResponsePage(new ErrorPage());
			return;
		}
		
		Long id = Long.parseLong(pageParameters.getString("id"));
		Goal goal = goalPersistenceManager.get(id);
		
		add(new FeedbackPanel("feedback"));
		
		GoalFormPanel goalFormPanel = new UpdateGoalFormPanel("goal_form_panel", goal);
		add(goalFormPanel);
		
		TagForm tagForm = new TagForm("create_tag_form", new Tag());
		add(tagForm);
		
		add(new GoalTagsSelectorPanel("goal_tag_selector", goal));
	}

}
